<extend name="Layout/page_detail" />
<block name="content">
	{:W('PageHeader/simple',array('name'=>$folder_name,'search'=>'M'))}
	<form method="post" name="form_adv_search" id="form_adv_search">
		<div class="adv_search panel panel-default  display-none"  id="adv_search">
			<div class="panel-heading">
				<div class="row">
					<h4 class="col-xs-6">高级搜索</h4>
					<div class="col-xs-6 text-right">
						<a  class="btn btn-sm btn-info" onclick="submit_adv_search();">搜索</a>
						<a  class="btn btn-sm " onclick="close_adv_search();">关闭</a>
					</div>
				</div>
			</div>
			<div class="panel-body">
				<div class="form-group col-sm-6">
					<label class="col-sm-4 control-label" for="li_name">标题：</label>
					<div class="col-sm-8">
						<input  class="form-control" type="text" id="li_name" name="li_name" >
					</div>
				</div>

				<div class="form-group col-sm-6">
					<label class="col-sm-4 control-label" for="li_content">内容：</label>
					<div class="col-sm-8">
						<input  class="form-control" type="text" id="li_content" name="li_content" >
					</div>
				</div>

				<in name="folder" value="darftbox,outbox">
					<div class="form-group col-sm-6">
						<label class="col-sm-4 control-label" for="li_to">收件人：</label>
						<div class="col-sm-8">
							<input  class="form-control" type="text" id="li_to" name="li_to" >
						</div>
					</div>
					<else/>
					<div class="form-group col-sm-6">
						<label class="col-sm-4 control-label" for="li_from">发件人：</label>
						<div class="col-sm-8">
							<input  class="form-control" type="text" id="li_from" name="li_from" >
						</div>
					</div>
				</in>

				<div class="form-group col-sm-6">
					<label class="col-sm-4 control-label" for="be_create_time">时间：</label>
					<div class="col-sm-8">
						<div class="input-daterange input-group" >
							<input type="text" class="input-sm form-control text-center" name="be_create_time" />
							<span class="input-group-addon">-</span>
							<input type="text" class="input-sm form-control text-center" name="en_create_time" />
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
	<div class="operate panel panel-default">
		<div class="panel-body">
			<div class="pull-left">
				<a onclick="mark('del');" class="btn btn-sm btn-warning">删除</a>
				<a onclick="mark('del_forever');" class="btn btn-sm btn-danger">彻底删除</a>
				<a onclick="forword();" class="btn btn-sm btn-primary">转发</a>
				<a onclick="mark('spam');" class="btn btn-sm btn-primary display-none">举报</a>
				<div class="btn-group">
					<a class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" href="#"> 标记为 <span class="fa fa-caret-down"></span> </a>
					<ul class="dropdown-menu">
						<li onclick="mark('readed');">
							<a>已读</a>
						</li>
						<li onclick="mark('unread');">
							<a>未读</a>
						</li>
					</ul>
				</div>
				<div class="btn-group" id="move_to">
					<a class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" href="#"> 转移到 <span class="fa fa-caret-down"></span> </a>
					<ul class="dropdown-menu">
						{$folder_list}
					</ul>
				</div>
			</div>
			<div class="pull-right">
				<a onclick="receve();" class="btn btn-sm btn-primary">收信</a>
			</div>
		</div>
	</div>

	<div class="ul_table">
		<ul>
			<li class="thead" >
				<label class="inline pull-left col-3">
					<input class="ace" type="checkbox" name="id-toggle-all" id="id-toggle-all" />
					<span class="lbl"></span></label>
				<span class="col-20 pull-left">
					<in name="folder" value="darftbox,outbox">
						收件人
						<else/>
						发件人
					</in></span>
				<span class="col-9 pull-right " >时间</span>
				<span class="autocut auto">标题</span>
			</li>
			<empty name="list">
				<li class="no-data">
					没找到数据
				</li>
				<else/>
				<form method="post" action="" name="form_data" id="form_data">
					<foreach name="list" item="vo">
						<li class="tbody <eq name='vo.read' value='1'>normal</eq><eq name='vo.read' value='0'>bold</eq>" >
							<label class="inline pull-left col-3">
								<input class="ace" type="checkbox" name="id[]" value="{$vo.id}" />
								<span class="lbl"></span></label>
							<span class="col-20 autocut pull-left">
								<in name="folder" value="darftbox,outbox">
									{$vo.to|show_contact}
									<else/>
									{$vo.from|show_contact}
								</in> </span>
							<span  class="col-9 pull-right" >{$vo.create_time|to_date='Y-m-d'}</span>
							<span class="autocut auto">
								<notempty name = "vo['add_file']" >
									<i class="fa fa-paperclip"></i>
									<else/>
									<i class="fa fa-paperclip" style="text-indent:-9999px;"></i>
								</notempty>
								<in name="folder" value="darftbox">
									<a  title="{$vo.name|htmlspecialchars}" href="{:U('edit','id='.$vo['id'])}"> {$vo.name}&nbsp;&nbsp;&nbsp;
									<eq name="vo.name|strlen" value="0">
										无标题
									</eq></a>
									<else/>
									<a title="{$vo.name|htmlspecialchars}" href="{:U('read','id='.$vo['id'])}"> {$vo.name}&nbsp;&nbsp;&nbsp;
									<eq name="vo.name|strlen" value="0">
										无标题
									</eq> </a>
								</in> </span>
						</li>
					</foreach>
				</form>
				<div class="pagination">
					{$page}
				</div>
			</empty>
		</ul>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		function mark(action) {
			var vars = $("#form_data").serialize();
			switch (action) {
			case "readed":
				sendAjax("{:U('mark','action=readed')}", vars, function(data) {
					if (data.status) {
						$("input[name='id[]']:checked").each(function() {
							$(this).parents("li").removeClass("bold");
							$(this).parents("li").addClass("normal");
						});
						$("input[name='id[]']:checked").prop('checked', false);
						$("#id-toggle-all").prop('checked', false);
					}
				});
				break;
			case "unread":
				sendAjax("{:U('mark','action=unread')}", vars, function(data) {
					if (data.status) {
						$("input[name='id[]']:checked").each(function() {
							$(this).parents("li").removeClass("normal");
							$(this).parents("li").addClass("bold");
						});
						$("input[name='id[]']:checked").prop('checked', false);
						$("#id-toggle-all").prop('checked', false);
					}
				});
				break;
			case "del":
				sendAjax("{:U('mark','action=del')}", vars, function(data) {
					if (data.status) {
						ui_alert(data.info, function() {
							location.reload(true);
						});
					}
				});
				break;
			case "del_forever":
				ui_confirm('确定要删除吗?', function() {
					sendAjax("{:U('mark','action=del_forever')}", vars, function(data) {
						if (data.status) {
							ui_alert(data.info, function() {
								location.reload(true);
							});
						}
					});
				});
				break;
			case "spam":
				sendAjax("{:U('mark','action=spam')}", vars, function(data) {
					if (data.status) {
						ui_alert(data.info, function() {
							location.reload(true);
						});
					}
				});
				break;
			default:
			}
		}

		function forword() {
			if ($("input[name='id[]']:checkbox:checked").length == 1) {
				window.open('{:U("reply")}?id="' + $("input[name='id[]']:checkbox:checked:first").val() + "&type=forward", "_self");
			} else {
				ui_error("请选择一封要转发的邮件");
				return false;
			};
		}

		function receve() {
			sendAjax("{:U('receve')}");
		}

		function move_to(val) {
			var vars = $("#form_data").serialize();
			sendAjax("{:U('mark','action=move_to')}", 'val=' + val + '&' + vars, function(data) {
				if (data.status) {
					ui_alert(data.info, function() {
						location.reload(true);
					});
				}
			});
		}


		$(document).ready(function() {
			$("#move_to li").click(function() {
				move_to($(this).attr("id"));
			});
			set_return_url();
		});
	</script>
</block>